﻿#include-once
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include "FastFind.au3"
#include "ImageSearch.au3"

Opt("PixelCoordMode", 0)
Opt("MouseCoordMode", 0)

Func FindHero(ByRef $x, ByRef $y, const $hWnd)
   Local $winPos = WinGetPos($hWnd)
   Local $mousePos = MouseGetPos()

   Local $pos = FFNearestSpot(4, 4, $mousePos[0], $mousePos[1], 0x554B29, 0, False)
   If @error Then
	  $x = 0
	  $y = 0

	  return False
   EndIf

   $x = $pos[0] + 50
   $y = $pos[1] + 100

   return True
EndFunc

Func FindEnemy(ByRef $x, ByRef $y, const $hWnd)
   Local $winPos = WinGetPos($hWnd)
   Local $mousePos = MouseGetPos()

   Local $pos = FFNearestSpot(4, 4, $mousePos[0], $mousePos[1], 0x634542, 0, False)
   If @error Then
	  $x = 0
	  $y = 0

	  return False
   EndIf

   $x = $pos[0] - 50
   $y = $pos[1] + 100

   return True
EndFunc

Func CheckRange($fromX, $fromY, $toX, $toY, $range, $height, ByRef $curRange, ByRef $curDist)
   If $fromX = 0 And $fromY = 0 Then
	  Return False
   EndIf

   If $toX = 0 And $toY = 0 Then
	  Return False
   EndIf

   $fromY = $fromY + $height

   Local $direction = GetDirection($fromX, $fromY, $toX, $toY)
   Local $factor = Abs($direction[0])
   $range = $range * ($factor * 0.19 + 0.81)

   Local $dist = 0
   Local $distX = 0
   Local $distY = 0

   $distX = $fromX - $toX
   $distY = $fromY - $toY
   $dist = Sqrt($distX * $distX + $distY * $distY)

   $curRange = $range
   $curDist = $dist

   If $dist > $range Then
	  Return False
   EndIf

   return True
EndFunc


Func GetDirection($fromX, $fromY, $toX, $toY)
   Local $direction = [$toX - $fromX, $toY - $fromY]
   Local $dist = Sqrt($direction[0] * $direction[0] + $direction[1] * $direction[1])

   If $dist = 0 Then
	  return $direction
   EndIf

   $direction[0] = $direction[0] / $dist
   $direction[1] = $direction[1] / $dist

   return $direction
EndFunc